<?php

declare(strict_types=1);

namespace App\Controller\delivery;
use App\Controller\BaseController;
use App\Model\AppletPlayletRel;
use App\Model\Playlet;
use App\Model\PlayletEpisodes;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use App\Common\Response\SystemCode;
use App\Service\delivery\PlayletService;

#[AutoController]
class PlayletController  extends BaseController
{

    #[Inject]
    private PlayletService $playletService;
    /**
     * 短剧列表
     */
    public function Index(RequestInterface $request)
    {

        $data = $this->playletService->search($request->query());

        return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$data);


    }

    public function Episodes(int $id){

        if(!empty($id)) {
            $playletInfo = Playlet::query()->select('id')->where('id', $id)->first();
            if (empty($playletInfo)) {
                return $this->response(SystemCode::SYSTEM_ERROR, '短剧不存在');
            }
            $playletEpisodesInfo = PlayletEpisodes::query()->select(['playlet_number as value','playlet_number_name as label'])->where(['playlet_id' => $id])->get();
            return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功', $playletEpisodesInfo);
        }

    }

    public function EpisodesList(int $id){

        if(!empty($id)) {
            $playletInfo = Playlet::query()->select('id')->where('id', $id)->first();
            if (empty($playletInfo)) {
                return $this->response(SystemCode::SYSTEM_ERROR, '短剧不存在');
            }
            $playletEpisodesInfo = PlayletEpisodes::query()->select(['playlet_number','playlet_number_name','original_play_url','play_url','cover'])->where(['playlet_id' => $id])->orderBy('playlet_number','asc')->get();
            return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功', $playletEpisodesInfo);
        }

    }

}